package coder.nav.model.bo;

import cn.hutool.core.collection.CollectionUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@Data
public class NavCashQueryBO implements Serializable {

    @ApiModelProperty("当前页")
    private Integer pageIndex = 1;

    @ApiModelProperty("页面大小")
    private Integer pageSize = 20;

    @ApiModelProperty("标题")
    private String title;

    @ApiModelProperty("备注")
    private String remark;

    @ApiModelProperty("消费标识: 0支出 1收入")
    private List<Integer> flags;

    @ApiModelProperty("支付渠道: 0银联 1微信 2支付宝")
    private List<Integer> channels;

    @ApiModelProperty("消费类型: 0其他 1饮食 2购物 3通讯 4通勤 5娱乐 6房租")
    private List<Integer> types;

    @ApiModelProperty("最小金额")
    private BigDecimal minMoney;

    @ApiModelProperty("最大金额")
    private BigDecimal maxMoney;

    @ApiModelProperty("年")
    private Integer year;

    @ApiModelProperty("月")
    private Integer month;

    @ApiModelProperty("日")
    private Integer day;

    @ApiModelProperty("创建日期")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date createDate;

    @ApiModelProperty("开始日期")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date startDate;

    @ApiModelProperty("结束日期")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date endDate;

    @ApiModelProperty("分组字段")
    private String groupBy;

    public List<Integer> getFlags() {
        if(CollectionUtil.isNotEmpty(this.flags)) {
            return this.flags.stream().filter(Objects::nonNull).collect(Collectors.toList());
        }
        return flags;
    }

    public List<Integer> getChannels() {
        if(CollectionUtil.isNotEmpty(this.channels)) {
            return this.channels.stream().filter(Objects::nonNull).collect(Collectors.toList());
        }
        return channels;
    }

    public List<Integer> getTypes() {
        if(CollectionUtil.isNotEmpty(this.types)) {
            return this.types.stream().filter(Objects::nonNull).collect(Collectors.toList());
        }
        return types;
    }

}
